package org.wabson.alfresco.translations;

import java.io.IOException;
import java.io.Reader;
import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

public class MessageBundle
{
    private String name;
    private Properties properties;
    private List<String> lines;
    
    public MessageBundle()
    {
        lines = new ArrayList<String>();
    }
    
    /**
     * Create a new named bundle object
     */
    public MessageBundle(String name)
    {
        this.name = name;
        lines = new ArrayList<String>();
    }
    
    public void addLine(String s)
    {
        lines.add(s);
    }
    
    private String getContents()
    {
        StringBuffer sb = new StringBuffer();
        for (String line : lines)
        {
            sb.append(line + "\n");
        }
        return sb.toString();
    }
    
    public Properties getProperties()
    {
        if (properties == null)
        {
            properties = new Properties();
            Reader reader = new StringReader(getContents());
            try
            {
                properties.load(reader);
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
        }
        return properties;
    }
    
    public int getSizeInBytes()
    {
       return 0;
    }
    
    public int getNumLines()
    {
       return lines.size();
    }
    
    public int getNumMessages()
    {
       return getProperties().size();
    }
    
    public List<String> getLines()
    {
        return lines;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }
   
}
